package com.zhanglinfeng.authorization.controller;

import com.zhanglinfeng.api.entity.UserEntity;
import com.zhanglinfeng.api.response.ResultResponse;
import com.zhanglinfeng.api.util.TokenUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

@Api(tags = {"授权服务"})
@RestController
public class LoginController {

    @ApiOperation(value = "登录", notes = "登录")
    @PostMapping(value = "/login", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    public ResultResponse<String> login(@RequestBody UserEntity user) {
        ResultResponse<String> resultResponse = new ResultResponse();
        if ("admin".equals(user.getUserName()) && "123456".equals(user.getPassword())) {
            String token = TokenUtil.createJWT(1L);
            resultResponse.setData(token);
            resultResponse.setMessage("端口号：2006");
        } else {
            resultResponse.setCode(500);
            resultResponse.setMessage("登录失败");
        }
        return resultResponse;
    }
}
